{extend name="main"}
{block name="style"}
<style type="text/css">
.w-60px{width: 60px;}
.w-80px{width: 80px;}
.w-150px{width: 150px;}
.wx-wechat{width: 320px;height: 560px;margin: 0 auto;position: relative;background-color: #eee;border:solid 1px #ddd;}
.wx-wechat .wx-wechat-header{width: 100%;height:64px;line-height:64px;background-color: #343434;color: #fff;text-align: center;}
</style>
{/block}
{block name="body"}
<div class="bg-white p-3">
	<el-form :model="form" @submit.native.prevent="submitForm" :rules="rules" ref="form" label-width="120px" :label-position="labelPosition">

	  <el-form-item label="Alias" prop="alias">
	    <el-input v-model="form.alias" class="col-12 col-sm-4 pl-0 pr-0" placeholder="Alias" maxlength="50" show-word-limit></el-input>
	  </el-form-item>

	  <el-form-item label="名称" prop="title">
	    <el-input v-model="form.title" class="col-12 col-sm-4 pl-0 pr-0" placeholder="Title" maxlength="100" show-word-limit></el-input>
	  </el-form-item>

	  <el-form-item label="内容" prop="content">
	    <el-input type="textarea" v-model="form.content" class="col-12 col-sm-6 pl-0 pr-0"  maxlength="200" show-word-limit
	    :autosize="{ minRows: 4, maxRows: 6 }"></el-input>
	  </el-form-item>

	  <el-form-item label="状态" prop="status">
	    <el-radio-group class="ml-0 ml-sm-2" v-model="form.status">
	      <el-radio :label="1">正常[默认]</el-radio>
	      <el-radio :label="0">停用</el-radio>
	    </el-radio-group>
	  </el-form-item>

	  <el-form-item>
	    <el-button type="primary" @click="submitForm('form')">立即保存</el-button>
	    <el-button @click="resetForm('form')">重置</el-button>
	  </el-form-item>
	</el-form>
	<div class="text-secondary small">
		<p>可用变量：uid,nickname,title,status</p>
		<p>First，Remark使用变量需要用花括号，例：“您的UID为{uid}”</p>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="Find"}
	var is_edit=false;
	var formData={
				alias:'',
				title:'',
				content:'',
				status:1,
			};
	{else/}
	var is_edit=true;
	var formData={:json_encode($Find,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			labelPosition:'right',
			form:formData,
			is_edit:is_edit,
	        rules: {
	          alias: [
	            { required: true, message: '请输入Alias', trigger: 'blur' },
	          ],
	          title: [
	            { required: true, message: '请输入名称', trigger: 'blur' },
	          ],
	          content: [
	            { required: true, message: '请输入内容', trigger: 'blur' },
	          ],
	        }
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
		methods:{
			updateFormData(){
				var _this=this;
				$.getJSON('',function(ret){
					if (ret){
						if (ret.code === 0) {
							_this.form=ret.data;
							return;
						}
					}
					window.location.reload();
				})
			},
			submitForm:function(formName) {
				var _this=this;
				var D=_this.form;
				_this.$refs[formName].validate((valid) => {
				  if (valid) {
					const loading = XYBase.openloading();
					$.ajax({
						url:'',
						data:D,
						type:'post',
						dataType:'json',
						success:function(ret){
					        loading.close();
					        if (ret) {
								if(ret.code == 0){
									XYBase.success(ret.msg);
									if(!_this.is_edit){
										_this.resetForm(formName);
									}else{
										_this.updateFormData();
									}
								}else{
									XYBase.msg(ret.msg);
								}
					        }else{
				          		XYBase.error(XYBase.config.system_network_error)
					        }
						},
						error:function(err){
					        loading.close();
				          	XYBase.error(XYBase.config.system_network_error)
						}
					});
				  } else {
					XYBase.warning('请先把表单填写完整。');
				    return false;
				  }
				});
			},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
		}
	});
$(function(){
	reloadWindowSize();
	$(window).resize(function(){
		reloadWindowSize();
	});
});
function reloadWindowSize (argument) {
	var winW=$(window).width();
	if(winW <= 576){
		vm.labelPosition='top';
	}else{
		vm.labelPosition='right';
	}
}
</script>
{/block}